package com.treasure.mall.biz.dto.live;

import com.treasure.mall.biz.dto.BaseDTO;
import com.treasure.mall.biz.entity.live.LiveSessionPO;
import com.treasure.mall.zbq.common.Jsr310Utils;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/6/14
 */
@Data
@NoArgsConstructor
public class SessionStatisticsDTO implements BaseDTO {
    private static final long serialVersionUID = 6317996722605329035L;

    private long onlineNum;
    private long dealNum;
    private BigDecimal dealAmount = BigDecimal.ZERO;
    /**
     * 累计人数
     */
    private long grandTotalNum;
    /**
     * 最高在线人数
     */
    private long maxOnlineNum;
    /**
     * 活跃度
     */
    private long activityNum;
    /***
     * 用户在线总时长，单位秒
     */
    private long userOnlineTotalSeconds;

    public SessionStatisticsDTO(LiveSessionPO po) {
        this.grandTotalNum = po.getCurrentMaxVisits();
        this.maxOnlineNum = po.getMaxOnlineNum();

        this.dealAmount = po.getDealAmount();
        this.dealNum = po.getDealNum();
        this.activityNum = po.getActivityNum();
        this.userOnlineTotalSeconds = po.getUserOnlineTotalSeconds();
    }

    public String getAvgDuration() {
        if (userOnlineTotalSeconds == 0) {
            return Jsr310Utils.Duration.getDurationBySeconds(userOnlineTotalSeconds);
        }
        return Jsr310Utils.Duration.getDurationBySeconds(userOnlineTotalSeconds / grandTotalNum);
    }

}
